﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLLUONG.DTO;
using QLLUONG.DAL;

namespace QLLUONG.BLL
{
    class ChucVuBLL
    {
        DataClasses1DataContext DB = new DataClasses1DataContext();
        public List<CHUCVU> Show()
        {
            return DB.CHUCVUs.ToList();
        }
        //public double HSL(String MSCV)
        //{
        //    CHUCVU CV = DB.CHUCVUs.Where(cv => cv.MSCV == MSCV).FirstOrDefault();
        //    return CV.HSL;
        //}
        //public double PhuCap(String MACV)
        //{
        //    CHUCVU CV = DB.CHUCVUs.Where(cv => cv.MSCV == MACV).FirstOrDefault();
        //    return CV.HSPC;
        //}
        public String MSCV(String TenCV)
        {
            CHUCVU CV = DB.CHUCVUs.Where(cv => cv.TENCV == TenCV).FirstOrDefault();
            return CV.MSCV;
        }
        public String TENCV(String MSCV)
        {
            CHUCVU CV = DB.CHUCVUs.Where(cv => cv.MSCV == MSCV).FirstOrDefault();
            return CV.TENCV;
        }
        public bool Insert(ChucVu CV)
        {
            CHUCVU CVU = new CHUCVU();
            try
            {
                CVU.MSCV = CV.Macv;
                CVU.TENCV = CV.Tencv;
                CVU.HSL = CV.Hsl;
                CVU.HSPC = CV.Hspc;
                DB.CHUCVUs.InsertOnSubmit(CVU);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool Update(ChucVu CV)
        {
            CHUCVU CVU = DB.CHUCVUs.Where(cv => cv.MSCV == CV.Macv).FirstOrDefault();
            try
            {
                CVU.TENCV = CV.Tencv;
                CVU.HSL = CV.Hsl;
                CVU.HSPC = CV.Hspc;
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool Delete(String MSCV)
        {
            CHUCVU CVU = DB.CHUCVUs.Where(cv => cv.MSCV == MSCV).FirstOrDefault();
            try
            {
                DB.CHUCVUs.DeleteOnSubmit(CVU);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool CheckCV(String MSCV)
        {
            var List = from CHUCVU in DB.CHUCVUs
                       where CHUCVU.MSCV.Contains(MSCV)
                       select CHUCVU;
            if (List.Any())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool CheckTenCV(String TenCV)
        {
            var List = from CHUCVU in DB.CHUCVUs
                       where CHUCVU.TENCV.Contains(TenCV)
                       select CHUCVU;
            if (List.Any())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
